<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<!-- remove old header -->


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>cogen API Reference Documentation
        - Class: Coroutine</title><meta name="MSSmartTagsPreventParsing" content="true" /><meta http-equiv="imagetoolbar" content="no" /><link href="css/default.css" rel="stylesheet" type="text/css" /><link href="css/pygments.css" rel="stylesheet" type="text/css" />
    <!-- <link rel="shortcut icon" href="/images/favicon.ico" type="image/vnd.microsoft.icon"/> -->
    <link rel="stylesheet" href="css/apydia.css" type="text/css" />
    <script src="js/jquery-1.2.1.pack.js" type="text/javascript"></script>
    <script src="js/apydia.js" type="text/javascript"></script>
	<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
    <div id="page">
        <div id="browser">
            <div class="browser-section">
                <h2>Module Index</h2>
                <ul>
                    <li>
                        <a href="cogen.html">cogen</a>
                    </li><li>
                        <a href="cogen.common.html">cogen.common</a>
                    </li><li>
                        <a href="cogen.core.html">cogen.core</a>
                    </li><li class="active">
                        <a href="cogen.core.coroutine.html">cogen.core.coroutine</a>
                    </li><li>
                        <a href="cogen.core.events.html">cogen.core.events</a>
                    </li><li>
                        <a href="cogen.core.queue.html">cogen.core.queue</a>
                    </li><li>
                        <a href="cogen.core.reactors.html">cogen.core.reactors</a>
                    </li><li>
                        <a href="cogen.core.schedulers.html">cogen.core.schedulers</a>
                    </li><li>
                        <a href="cogen.core.sockets.html">cogen.core.sockets</a>
                    </li><li>
                        <a href="cogen.core.util.html">cogen.core.util</a>
                    </li><li>
                        <a href="cogen.web.html">cogen.web</a>
                    </li><li>
                        <a href="cogen.web.async.html">cogen.web.async</a>
                    </li><li>
                        <a href="cogen.web.wsgi.html">cogen.web.wsgi</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Methods</h2>
                <ul>
                    <li>
                        <a href="cogen.core.coroutine.Coroutine.html#method-add_waiter">add_waiter</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#method-finalize">finalize</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#method-handle_error">handle_error</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#method-process">process</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#method-remove_waiter">remove_waiter</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#method-run_op">run_op</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Attributes</h2>
                <ul>
                    <li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-STATE_COMPLETED">STATE_COMPLETED</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-STATE_FAILED">STATE_FAILED</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-STATE_FINALIZED">STATE_FINALIZED</a>
                    </li><li>
                        <a href="cogen.web.wsgi.WSGIServer.html#attribute-STATE_NEED_INIT">STATE_NEED_INIT</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-STATE_RUNNING">STATE_RUNNING</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-caller">caller</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-coro">coro</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-exception">exception</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-f_args">f_args</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-f_kws">f_kws</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-name">name</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-prio">prio</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-result">result</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-running">running</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-state">state</a>
                    </li><li>
                        <a href="cogen.core.coroutine.Coroutine.html#attribute-waiters">waiters</a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="content">
    <h1>Class: cogen.core.coroutine.Coroutine</h1>
    <div class="docstring plain">We need a coroutine wrapper for generators and function alike because
we want to run functions that don't return generators just like a
coroutine.</div>
    <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L34">View source</a>
    </li>
</ul>
    <div>
        <h2>Methods</h2>
            <h3 id="method-add_waiter">
                add_waiter
                <span class="args">(self, coro)</span>
            </h3>
            <div class="docstring plain"></div>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L68">View source</a>
    </li>
</ul>
            <h3 id="method-finalize">
                finalize
                <span class="args">(self)</span>
            </h3>
            <div class="docstring plain"></div>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L86">View source</a>
    </li>
</ul>
            <h3 id="method-handle_error">
                handle_error
                <span class="args">(self)</span>
            </h3>
            <div class="docstring plain"></div>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L174">View source</a>
    </li>
</ul>
            <h3 id="method-process">
                process
                <span class="args">(self, sched, coro)</span>
            </h3>
            <div class="docstring plain"></div>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L90">View source</a>
    </li>
</ul>
            <h3 id="method-remove_waiter">
                remove_waiter
                <span class="args">(self, coro)</span>
            </h3>
            <div class="docstring plain"></div>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L73">View source</a>
    </li>
</ul>
            <h3 id="method-run_op">
                run_op
                <span class="args">(self, op)</span>
            </h3>
            <div class="docstring plain">Handle the operation:
<ul><li> if coro is in STATE_RUNNING, send or throw the given op</li><li> if coro is in STATE_NEED_INIT, call the init function and if it </li></ul><blockquote>doesn't return a generator, set STATE_COMPLETED and set the resultto whatever the function returned. </blockquote><ul><li> if StopIteration is raised, set STATE_COMPLETED and return self.</li><li> if any other exception is raised, set STATE_FAILED, handle error</li></ul><blockquote>or send it to the caller, return self</blockquote>
Return self is used as a optimization. Coroutine is also a Operation
which handles it's own completion (resuming the caller and the waiters).</div>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen\cogen\core\coroutine.py#L113">View source</a>
    </li>
</ul>
    </div>
    <div>
        <h2>Attributes</h2>
            <h3 id="attribute-STATE_COMPLETED">STATE_COMPLETED</h3>
            <div class="docstring plain"></div>
            <h4>Value of STATE_COMPLETED</h4>
            <pre class="code"><code>2</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_FAILED">STATE_FAILED</h3>
            <div class="docstring plain"></div>
            <h4>Value of STATE_FAILED</h4>
            <pre class="code"><code>3</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_FINALIZED">STATE_FINALIZED</h3>
            <div class="docstring plain"></div>
            <h4>Value of STATE_FINALIZED</h4>
            <pre class="code"><code>4</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_NEED_INIT">STATE_NEED_INIT</h3>
            <div class="docstring plain"></div>
            <h4>Value of STATE_NEED_INIT</h4>
            <pre class="code"><code>0</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-STATE_RUNNING">STATE_RUNNING</h3>
            <div class="docstring plain"></div>
            <h4>Value of STATE_RUNNING</h4>
            <pre class="code"><code>1</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-caller">caller</h3>
            <div class="docstring plain"></div>
            <h4>Value of caller</h4>
            <pre class="code"><code>&lt;member 'caller' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-coro">coro</h3>
            <div class="docstring plain"></div>
            <h4>Value of coro</h4>
            <pre class="code"><code>&lt;member 'coro' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-exception">exception</h3>
            <div class="docstring plain"></div>
            <h4>Value of exception</h4>
            <pre class="code"><code>&lt;member 'exception' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-f_args">f_args</h3>
            <div class="docstring plain"></div>
            <h4>Value of f_args</h4>
            <pre class="code"><code>&lt;member 'f_args' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-f_kws">f_kws</h3>
            <div class="docstring plain"></div>
            <h4>Value of f_kws</h4>
            <pre class="code"><code>&lt;member 'f_kws' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-name">name</h3>
            <div class="docstring plain"></div>
            <h4>Value of name</h4>
            <pre class="code"><code>&lt;member 'name' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-prio">prio</h3>
            <div class="docstring plain"></div>
            <h4>Value of prio</h4>
            <pre class="code"><code>&lt;member 'prio' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-result">result</h3>
            <div class="docstring plain"></div>
            <h4>Value of result</h4>
            <pre class="code"><code>&lt;member 'result' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-running">running</h3>
            <div class="docstring plain"></div>
            <h4>Value of running</h4>
            <pre class="code"><code>&lt;property object at 0x00C6A300&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-state">state</h3>
            <div class="docstring plain"></div>
            <h4>Value of state</h4>
            <pre class="code"><code>&lt;member 'state' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
            <h3 id="attribute-waiters">waiters</h3>
            <div class="docstring plain"></div>
            <h4>Value of waiters</h4>
            <pre class="code"><code>&lt;member 'waiters' of 'Coroutine' objects&gt;</code></pre>
            <ul class="link-bar">
    <li class="top"><a href="#header">Top</a></li>
    <li class="link-to-sourcecode">
        <a href="http://cogen.googlecode.com/svn/trunk/cogen#L0">View source</a>
    </li>
</ul>
    </div>
        </div>
        <div id="footer">
            Generated with <a href="http://apydia.ematia.de/" class="extern">
            Apydia 0.0.3</a>
        </div>
    </div>
</body>
</html>